package me.zd.tool.hardlink.view.i18n;

import me.zd.tool.hardlink.service.I18nService;
import me.zd.tool.hardlink.view.I18nAdapter;

import java.util.function.Consumer;

class I18nSingleTextComponentAdapter implements I18nAdapter {
    private final Consumer<String> updater;
    private final String[] i18nKey;
    private int index = 0;

    public I18nSingleTextComponentAdapter(Consumer<String> updater, String... i18nKey) {
        this.updater = updater;
        this.i18nKey = i18nKey;
    }

    @Override
    public void updateI18n() {
        updater.accept(I18nService.INS.get(i18nKey[index]));
    }

    @Override
    public void updateI18n(int index) {
        if (index < i18nKey.length) {
            this.index = index;
        }
        updateI18n();
    }
}
